package com.tjh.springbootapi.controller;

import com.koala.apiprototype.annotations.IgnoreValidate;
import com.tjh.springbootapi.annotation.NeedWebSocket;
import com.tjh.springbootapi.service.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Create by koala on 2022-08-14
 */
@RestController
@RequestMapping("/webSocket")
public class WebSocketController {

    @Autowired
    private WebSocketService webSocketService;

    @PostMapping("/getWebSocketKey")
    @IgnoreValidate
    @NeedWebSocket
    public String getWebSocketKey() {
        return webSocketService.getWebSocketKey();
    }

    @PostMapping("/sedDataToWebSocket")
    @IgnoreValidate
    public void sedDataToWebSocket(@RequestBody Map<String, String> infoData) {
        String info = infoData.get("infoData");
        webSocketService.sedDataToWebSocket(info);
    }

}